/*
 * @Copyright: 2016 www.yyfax.com Inc. All rights reserved.
 */
package com.jaws.core.compatible.enums;

import org.apache.commons.lang3.StringUtils;

/**
 * 用于管理主键生产策略
 * 
 * @author jiangmy
 * @date 2016-12-02 16:49:49
 * @since v1.0.0
 */
public enum SequenceStrategy {
	/** 默认策略: D000012345 */
	DEFAULT("DEFAULT", "D", 30, 12),
	/** USER_ID策略: U000012345 */
	USER_INFO("USER_INFO", "U", 10, 10),
	/** TAG_ID策略: TAG12345 */
	SYS_TAGS("SYS_TAGS", "TAG", 10, 8),
	/** APP_ID策略: APP12345 */
	OAUTH_APP("OAUTH_APP", "APP", 10, 8),
	/** APP_ID策略: APP12345 */
	OAUTH_("OAUTH_APP", "APP", 10, 8),
	/** MSG_SMS_ID策略: yyyyMMddHHmmSSS000001 */
	MSG_SMS("MSG_SMS", "", 50, 10), //
	/** ENTERPRISE策略: E */
	ENTERPRISE("ENTERPRISE", "EI", 10, 12), //
	/** 支付模块用户PAY_USER策略: U000012345 */
	PAY_USER("PAY_USER", "PU", 10, 10),
	/**  友金社模块-资产包package策略: EXPA00000031 */
	EXCH_ASSET_PACKAGE("EXCH_ASSET_PACKAGE", "EXPA", 10, 12),
	/**  友金社模块-投资订单策略: EXOR00000031 */
	EXCH_INVEST_ORDER("EXCH_INVEST_ORDER", "EXOR", 10, 14),
	/**  友金社模块-投资记录策略: EXRC00000031 */
	EXCH_INVEST_RECORD("EXCH_INVEST_RECORD", "EXRC", 10, 14),
	/**  友金社模块-还款计划策略: EXRP00000031 */
	EXCH_REPAY_PLAN("EXCH_REPAY_PLAN", "EXRP", 10, 14),
	/**  友金社模块-银行卡账户ID策略: EXAB00000031 */
	EXCH_ACCOUNT_BANK("EXCH_ACCOUNT_BANK", "EXAB", 10, 14),
	/**  友金社模块-虚拟账户ID策略: EXAV00000031 */
	EXCH_ACCOUNT_VIRTUAL("EXCH_ACCOUNT_VIRTUAL", "EXAV", 10, 14),
	;

	private final String key;

	private final String prefix;

	private final int step;

	private final int len;

	/**
	 * 构造函数
	 * 
	 * @param key 业务主键key
	 * @param prefix 前缀
	 * @param step 连续生成主键的步长(主键生产越快,这里越大,默认推荐20)
	 * @param len 最终生成的业务主键长度
	 */
	private SequenceStrategy(String key, String prefix, int step, int len) {
		this.key = key;
		this.prefix = prefix;
		this.step = step;
		this.len = len;
	}

	public String getKey() {
		return key;
	}

	public String getPrefix() {
		return prefix;
	}

	public int getLen() {
		return len;
	}

	public int getStep() {
		return step;
	}

	public static SequenceStrategy fromKey(String key) {
		for (SequenceStrategy s : values()) {
			if (StringUtils.equalsIgnoreCase(key, s.getKey())) {
				return s;
			}
		}
		return DEFAULT;
	}
}
